<%@ page pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath();
    request.setAttribute("basePath", basePath); // 将BasePath的内容保存在application属性之中
%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <base href="<%=basePath%>/"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>DEMO</title>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <link rel="stylesheet" href="css/common.css"/>
    <link rel="stylesheet" href="css/welcome.css"/>
    <link rel="stylesheet" href="css/jquery.ptTimeSelect.css"/><!-- 日历样式 -->
    <link rel="stylesheet" href="css/validationEngine.jquery.css"/><!--表单验证css-->
    <link rel="stylesheet" href="css/joyride-2.1.css"/>
    <link rel="stylesheet" href="css/joyride-2.1.css"/>
    <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
    <script type="text/javascript" src="js/jquery.ptTimeSelect.js"></script><!--日历插件-->
    <script type="text/javascript" src="js/pickday.js"></script><!--日历插件配置和调用-->
    <script type="text/javascript" src="js/WdatePicker.js"></script><!--日历插件配置和调用-->
    <script type="text/javascript" src="js/jquery.pagination.js"></script>
    <script type="text/javascript" src="js/jquery.cookie.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/jquery.joyride-2.1.js"></script>
    <script type="text/javascript">

        //科室管理，查询科室列表
        function dptManage(_this) {
            $.post('${ctx}/department/list', {}, function (dataS) {
                var res = eval(dataS);
                if (res.resultCode == "SUCC") {
                    var dpts = res.data.departmentList;
                    $("#departmentList").html("");
                    $.each(dpts, function (i, dpt) {
                        var dptDiv = '<div class="form-group">' +
                            '<label class="control-label" style="width:100px" >科室：</label> ' +
                            '<div class="inline" deptId="' + dpt.id + '" >' +
                            '<span class="input200 inline  font14">' + dpt.departmentName + '</span>' +
                            ' <button type="button" class="btn btn_white20" onclick="editbranch(this)">修改</button> ' +
                            '<button type="button" class="btn btn-linkr" onclick="deletebranch(this)" style="margin-left: 5px;">删除</button>' +
                            '</div>' +
                            '</div>';
                        $("#departmentList").append($(dptDiv));
                    });
                }
            }, 'json');
            showPop(_this, 'addSertype');
            $(".pop_content").scrollTop(0);
        }

        //修改科室
        function editbranch(obj) {
            var text = $(obj).siblings("span").text();
            if ($(obj).siblings("span").length == 1) {
                $(obj).siblings("span").remove();
                var inp = $("<input type='text' class='form-control input200' value='" + text + "'/>")
                var html = ' <button type="button" class="btn btn_save2 ver_top" onclick="saveDpt(this)">保存</button>'
                $(obj).parent().html("").prepend(inp).append(html);
            }
        }

        //保存科室
        function saveDpt(obj) {
            var text = $.trim($(obj).siblings(':text').val());//所填内容
            if (text.length > 8) {
                zhyAlert("科室名称不能超过8个字符");
                return;
            }

            if (text == "") {
                zhyAlert("请填写科室名称");
                return;
            }
            var param = {};
            var _deptId = $(obj).parent().attr("deptId");
            if (_deptId) {
                param = {'deptId': _deptId, 'departmentName': text};
            } else {
                param = {'departmentName': text};
            }
            $.post('${ctx}/department/edit', param, function (dataS) {
                var res = eval(dataS);
                if (res.resultCode == "SUCC") {
                    //$(obj).siblings(':text').val("");
                    $(obj).parents('.form-group').remove();

                    var dptDiv = '<div class="form-group">' +
                        '<label class="control-label" style="width:100px" >科室：</label> ' +
                        '<div class="inline" deptId="' + res.data.id + '" >' +
                        '<span class="input200 inline  font14">' + text + '</span>' +
                        ' <button type="button" class="btn btn_white20" onclick="editbranch(this)">修改</button> ' +
                        '<button type="button" class="btn btn-linkr" onclick="deletebranch(this)" style="margin-left: 5px;">删除</button>' +
                        '</div>' +
                        '</div>';
                    $("#departmentList").prepend($(dptDiv));
                } else {
                    zhyAlert(res.failureMessage);
                }
            }, 'json');
        }

        //删除科室
        function deletebranch(obj) {
            var _deptId = $(obj).parent().attr("deptId");
            $.post("${ctx}/department/delete", {'deptId': _deptId}, function (dataS) {
                var res = eval(dataS);
                if (res.resultCode == "SUCC") {
                    $(obj).parents('.form-group').remove();
                } else {
                    zhyAlert(res.failureMessage);
                }
            }, "json");
        }

        //添加科室
        function addbranch() {
            var html = '<div class="form-group">' +
                '<label class="control-label" style="width:100px" >科室：</label> ' +
                '<div class="inline">' +
                '<input type="text" class="form-control input200 "  placeholder="请输入科室名称" name="keshiname"> ' +
                '<button type="button" class="btn btn_save2 ver_top" onclick="saveDpt(this)">保存</button>' +
                '</div>' +
                '</div>';
            $("#dptForm").prepend(html);
        }




        /********* 分页函数开始 **********/


        var total = ${totalCount == null ? 0 : totalCount};
        var pageIndex = ${pageResult.pageNum == null ? 1 : pageResult.pageNum};
        var pageSize = ${pageResult.pageSize == null ? 2 : pageResult.pageSize};
        $(function () {
            if (total > 0) {

                initPage();
            }
        });
        //dfasdfasdf
        function initPage() {
            console.log("初始化页面");
            //分页，PageCount是总条目数，这是必选参数，其它参数都是可选
            $("#emp_pagination").pagination(total, {
                callback: PageCallback1,
                link_to: "javascript:searchSub(__id__)",
                prev_text: '上一页',       //上一页按钮里text
                next_text: '下一页',       //下一页按钮里text
                items_per_page: pageSize,  //显示条数
                num_display_entries: 6,    //连续分页主体部分分页条目数
                current_page: pageIndex - 1,   //当前页索引
                num_edge_entries: 2        //两侧首尾分页条目数
            });

            //翻页调用
            function PageCallback1(index, jq) {
                return true;
            }
        }

        function searchSub(pageNum) {
            //入职查询时间
            var inductionStart = $("#inductionStart").val();
            var inductionEnd = $("#inductionEnd").val();
            if (inductionEnd != '' && inductionStart != '') {
                if (inductionEnd < inductionStart) {
                    zhyAlert("入职查询开始时间不能大于结束时间！");
                    return;
                }
            }
            $("#searchForm [name=employeeType]").val($("#qEmpType").attr("value"));
            $("#searchForm [name=departmentId]").val($("#qDptId").attr("value"));
            $("#searchForm [name=qEmpStatus]").val($("#qEmpStatus").attr("value"));
            if (pageNum && parseInt(pageNum) > 0) {
                $("#searchForm [name=pageNum]").val(pageNum + 1);
            }
            $("#searchForm").submit();
        }

        /********** 分页函数结束 **********/
        //科室下拉搜索
        function submitDept(id) {
            $("#searchForm [name=departmentId]").val(id);
            $("#searchForm").submit();
        }

        //员工角色下拉搜索
        function submitRoles(id) {
            $("#searchForm [name=employeeType]").val(id);
            $("#searchForm").submit();
        }

        //员工状态下拉搜索
        function submitStatus(id) {
            $("#searchForm [name=qEmpStatus]").val(id);
            $("#searchForm").submit();
        }

        // 初始化员工密码
        function initEmployeePassword(obj, className, accountId) {
            $.ajax({
                type: "post",
                dataType: "json",
                url: "${ctx}/pages/account/initPassword.action",
                async: true,
                data: {
                    "accountId": accountId
                },
                success: function (data) {
                    //$("." + className).empty().html(data);

                    if(data == true){
                        showPop(obj, className);
                    } else {
                        window.location="pages/account/error.action"
                    }

                }
            });
        }

        function rmove() {
            if ($("input[name='keshiname']").val() == "") {
                $("input[name='keshiname']").parent().parent().remove();
            }
            hidePop();
        }


    </script>

</head>
<body>

<!-- 科室管理弹出框 start  -->
<div class="zhy_popa addSertype">
    <div class="pop_content" style="height: 320px; overflow-y: scroll">
        <form id="dptForm">
            <div class="form-group">
                <label class="control-label" style="width:100px">科室：</label>
                <div class="inline">
                    <input name="dptId" type="hidden" value="${dpt.id}"/>
                    <input type="text" class="form-control input200 validate[required,maxSize[8]]" placeholder="请输入科室名称"
                           value="">
                    <button type="button" class="btn btn_save2 ver_top" onclick="saveDpt(this)">保存</button>
                </div>
            </div>
            <div id="departmentList"></div>
            <div class="form-group">
                <label class="control-label" style="width:100px"></label>
                <button type="button" class="btn_white2 ml15" onclick="addbranch()"><i></i>继续填加</button>
            </div>
            <div class="operate_btn pull-right">
                <button type="button" class="btn cancle_yes" onclick="rmove()">关闭</button>
            </div>
        </form>
    </div>
</div>
<!-- 科室管理弹出框 end  -->
<div class="main_content member_list">
    <div class="col-xs-12 col-sm-12 ">
        <div class="panel panel-default div_bordered">
            <!-- Default panel contents -->
            <div class="panel-heading">
                <div class="jkbg_title_boxa" style="margin-bottom: 10px;">
                    <h4>账号管理</h4>
                </div>
                <div class="site_change">
                </div>
                <div class="form-inline pl20">
                    <form id="searchForm" action="${ctx}/pages/account/list_search.action">
                        <input type="hidden" name="pageNum" value=""/>
                        <input type="hidden" name="employeeType" value="${pageResult.empType}"/>
                        <input type="hidden" name="departmentId" value="${qDptId}"/>
                        <input type="hidden" name="qEmpStatus" value="${pageResult.empStatus}"/>
                        <div class="form-group">
                            <input name="keyWord" type="text" placeholder="员工姓名/联系电话" class="form-control input150"
                                   value="${pageResult.keyWord}"/>
                        </div>

                        <div class="form-group">
                            <div class="btn-group ">
                                <button id="qEmpType" type="button" class="btn btn-default dropdown-text"
                                        style="width: 85px;" value="${pageResult.empType}">账号角色
                                </button>
                                <button type="button" class="btn btn-default dropdown-toggle">
                                    <span class="caret"></span>
                                    <span class="sr-only">切换下拉菜单</span>
                                </button>
                                <ul class="dropdown-menu">
                                    <li><a href="javascript:void(0);" onclick="submitRoles()" value="">全部</a></li>
                                    <li><a href="javascript:void(0);" onclick="submitRoles('1')" value="1">员工账号</a></li>
                                    <li><a href="javascript:void(0);" onclick="submitRoles('2')" value="2">管理员</a></li>
                                    <li><a href="javascript:void(0);" onclick="submitRoles('3')" value="3">院长</a></li>
                                </ul>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="btn-group ">
                                <button id="qEmpStatus" type="button" class="btn btn-default dropdown-text"
                                        style="width: 85px;" value="${pageResult.empStatus}">员工状态
                                </button>
                                <button type="button" class="btn btn-default dropdown-toggle">
                                    <span class="caret"></span>
                                    <span class="sr-only">切换下拉菜单</span>
                                </button>
                                <ul class="dropdown-menu">
                                    <li><a href="javascript:void(0);" onclick="submitStatus('0')" value="0">全部</a></li>
                                    <li><a href="javascript:void(0);" onclick="submitStatus('1')" value="1">在职</a></li>
                                    <li><a href="javascript:void(0);" onclick="submitStatus('2')" value="2">请假</a></li>
                                    <li><a href="javascript:void(0);" onclick="submitStatus('9')" value="9">离职</a></li>
                                </ul>
                            </div>
                        </div>
                        <div class="form-group">入职时间：
                            <div class="inline relative mr0">
                                <input name="inductionStart" type="text" class="form-control mr0" style="width: 105px;"
                                       id="inductionStart" input-type='date' value="<fmt:formatDate value="${pageResult.beginDate}" pattern="yyyy-MM-dd"/>"/><!-- endDate
                                       id不要修改 -->
                            </div>
                            <em>至</em>
                            <div class="inline relative mr0">
                                <input name="inductionEnd" type="text" class="form-control mr0" style="width: 105px;"
                                       id="inductionEnd" input-type='date' value="<fmt:formatDate
                                       value="${pageResult.endDate}" pattern="yyyy-MM-dd"/>"/><!-- endDate
                                       id不要修改 -->
                            </div>
                        </div>
                        <div class="form-group">
                            <button type="button" class="btn btn_white20" onclick="searchSub(0)">搜索</button>
                        </div>
                        <div class="pull-right mr15">
                            <zhyAuth:hasPermission name="employee:employee_man">
                                <a class="btn btn_blueg2 mr0" href="pages/account/add_pre.action">+新增账号</a>
                            </zhyAuth:hasPermission>
                        </div>
                    </form>
                </div>
            </div>
            <table class="table table-bordered table-hover table_fixed table-multicols">
                <tHead>
                <tr>
                    <th width="10%" class="border_right">员工姓名</th>
                    <th width="10%" class="border_right">登陆手机</th>
                    <th width="20%" class="border_right">身份证号</th>
                    <th width="10%" class="border_right">员工角色</th>
                    <th width="10%" class="border_right">入职时间</th>
                    <th width="10%" class="border_right">离职时间</th>
                    <th>操作</th>
                </tr>
                </tHead>
                <tBody>

                <c:forEach items="${allAccounts}" var="account">
                    <tr id="${plan.pid}" status="${plan.status}">
                        <td>${account.name}</td>
                        <td>${account.phone}</td>
                        <td>${account.idCard}</td>
                        <td>
                            <c:if test="${account.personalType == 1}">
                                员工账号
                            </c:if>
                            <c:if test="${account.personalType == 2}">
                                管理员
                            </c:if>
                            <c:if test="${account.personalType == 3}">
                                院长
                            </c:if>
                        </td>
                        <td><fmt:formatDate value="${account.createTime}" pattern="yyyy-MM-dd"/></td>
                        <td>
                            <c:if test="${account.leaveTime == null}">
                                -
                            </c:if>
                            <c:if test="${account.leaveTime != null}">
                            <fmt:formatDate value="${account.leaveTime}" pattern="yyyy-MM-dd hh:mm:ss"/></td>
                        </c:if>
                        </td>


                        <td>


                        <span><a href="javascript:void(0)"
                                 onclick="initEmployeePassword(this,'create_zh_s','${account.accountId}');"
                                 class="colorblue">初始化密码</a></span>
                            <span><a href="javascript:void(0)" onclick="showEmpLeaveDetail(this);" class="colorblue">详情</a></span>
                            <span><a href="javascript:void(0)" onclick="showEmpLeaveDetail(this);" class="colorblue">修改</a></span>
                            <span><a href="javascript:void(0)" onclick="showEmpLeaveDetail(this);" class="colorblue">离职</a></span>
                            <span><a href="javascript:void(0)" onclick="showEmpLeaveDetail(this);" class="colorblue">删除</a></span>
                        </td>
                    </tr>
                </c:forEach>
                </tBody>
            </table>
            <div class="divider" style="width: 100%;"></div>
            <div class="row text-center">
                <div id="emp_pagination" class="pagination"></div>

                <span
                        class="allentries">${totalCount == null ? "":"共"}${totalCount == null ? "" : totalCount}${totalCount == null ? "":"条数据"}</span>
            </div>
        </div>
    </div>
</div>


<!--遮罩层-->
<div class="zhy_zhezhao_pop " style="height:800px;"></div>
<!--遮罩层 end-->
<!-- 密码初始化弹框 start -->
<div class="zhy_popa initPassword" style="width: 506px;margin-left: -253px;">
</div>
<!-- 密码初始化弹框 end -->

<!--离职弹框-->
<div class="zhy_popa dialog_0 " style="width: 450px;margin-left: -225px;">
    <p class="color66">温馨提示<span class="pull-right close_icon" onclick="hidePop()"></span></p>
    <div class="pop_content">
        <p>您确定是否让<span id="leaveName">${employee.employeeName}</span>离职？</p>
        <div class="operate_btn pull-right">
            <button type="button" class="btn cancle_yes" onclick="changeStatus()">确定</button>
            <button type="button" class="btn cancle_btn" onclick="hidePop()">取消</button>
        </div>
    </div>
</div>
<!-- 重新入职弹框 start -->
<div class="zhy_popa dialog_3 " style="width: 450px;margin-left: -225px;">
    <p class="color66">温馨提示<span class="pull-right close_icon" onclick="hidePop()"></span></p>
    <div class="pop_content">
        <p>您确定是否让<span id="joinName">${employee.employeeName}</span>重新入职？</p>
        <div class="operate_btn pull-right">
            <button type="button" class="btn cancle_yes" onclick="changeStatus()">确定</button>
            <button type="button" class="btn cancle_btn" onclick="hidePop()">取消</button>
        </div>
    </div>
</div>
<!-- 重新入职弹框 end -->
<!-- 删除员工 start -->
<div class="zhy_popa dialog_4 " style="width: 450px;margin-left: -225px;">
    <p class="color66">温馨提示<span class="pull-right close_icon" onclick="hidePop()"></span></p>
    <div class="pop_content">
        <p>您确定删除<span id="deleteName">${employee.employeeName}</span>？</p>
        <div class="operate_btn pull-right">
            <button type="button" class="btn cancle_yes" onclick="deleteEmp()">确定</button>
            <button type="button" class="btn cancle_btn" onclick="hidePop()">取消</button>
        </div>
    </div>
</div>
<!-- 删除员工 end -->
<!-- 请假弹框 start -->
<div class="zhy_popa applyLeave" style="width: 506px;margin-left: -253px;">
    <p class="color66">请假<span class="pull-right close_icon" onclick="hidePop()"></span></p>
    <div class="pop_content">
        <table border="0">
            <tr height="40px">
                <td align="right">请假人：</td>
                <td class="pl20"><span id="applyLeaveName">${employee.employeeName}</span></td>
            </tr>
            <tr height="40px">
                <td valign="middle" align="right">日期时间：</td>
                <td class="pl20">
                    <div class="form-group mb0">
                        <div class="inline relative mr0">
                            <input type="text" id="starttime" class="form-control input150"
                                   onclick="WdatePicker({el:'starttime',dateFmt:'yyyy-MM-dd HH:mm',maxDate:'#F{$dp.$D(\'endtime\')}',minDate:'%y-%M-{%d}'})"/>
                        </div>
                        <div class="inline">至</div>
                        <div class="inline relative mr0">
                            <input type="text" id="endtime" class="form-control input150 mr0"
                                   onclick="WdatePicker({el:'endtime',dateFmt:'yyyy-MM-dd HH:mm',minDate:'#F{$dp.$D(\'starttime\')}'})"/>
                        </div>
                    </div>
                </td>
            </tr>
        </table>
        <div class="operate_btn pull-right">
            <button type="button" class="btn cancle_yes" onclick="empApplyLeave()">确定</button>
            <button type="button" class="btn cancle_btn" onclick="hidePop()">取消</button>
        </div>
    </div>
</div>
<!-- 请假弹框 end -->
<!-- 销假弹框 start -->
<div class="zhy_popa cancelLeave" style="width: 506px;margin-left: -253px;">
    <p class="color66">销假<span class="pull-right close_icon" onclick="hidePop()"></span></p>
    <div class="pop_content">
        <table border="0">
            <tr height="40px">
                <td align="right">请假人：</td>
                <td class="pl20"><span id="cancelLeaveName">${employee.employeeName}</span></td>
            </tr>
            <tr height="40px">
                <td valign="middle" align="right">请假开始时间：</td>
                <td class="pl20" id="leaveStart"></td>
            </tr>
            <tr height="40px">
                <td valign="middle" align="right">请假结束时间：</td>
                <td class="pl20" id="leaveEnd"></td>
            </tr>
        </table>
        <div class="operate_btn pull-right">
            <button type="button" class="btn cancle_yes" onclick="empCancelLeave()">确定</button>
            <button type="button" class="btn cancle_btn" onclick="hidePop()">取消</button>
        </div>
    </div>
</div>
<!-- 销假弹框 end -->
<!-- 开通账号弹框 start-->
<div class="zhy_popa sitepop">
    <p class="color66">开通账号权限<span class="pull-right close_icon" onclick="hidePop()"></span></p>
    <div class="col-xs-12 col-sm-12 pop_content">
        <table border="0" cellspacing="0" cellpadding="0" class="font14" width="100%">
            <!--  <tr>
                 <td colspan="2"><p class="colorred font14" style="text-indent: 0px;">注意：开通账号权限后，需要消耗您购买的账号权限的个数</p></td>
             </tr> -->
            <tr>
                <td width="50%" align="left">
                    <label>姓名：</label>
                    <div class="inline " id="empAcctName">${employee.employeeName}</div>
                </td>
                <td width="50%" align="left">
                    <label>联系方式：</label>
                    <div class="inline " id="empPhone">${employee.phone}</div>
                </td>
            </tr>
        </table>
        <table border="0" cellspacing="0" cellpadding="0" class="font14" width="100%">
            <tr>
                <td align="left" width="15%" class="ver_top">
                    <label>选择账号角色：</label>
                </td>
                <td align="left" id="personRole">
                    <c:forEach items="${roles}" var="role">
                        <label class="label_check">
                            <input onclick="setupLabel()" name="hobby" value="${role.id}"
                                   type="checkbox">${role.roleName}
                        </label>
                    </c:forEach>
                </td>
            </tr>
        </table>
        <p style="color: #26BFAB;font-size: 15px;padding-left: 0px;text-indent: 0px;margin-top: 20px;margin-bottom: 0px;">
            选择服务站：</p>
        <div style="height:2px;background: #26BFAB;margin: 5px -15px 10px;"></div>
        <form class="form-inline text-left">
            <div class="form-group" style="margin-top: 10px;">
                <div id="jsAddress_3" class="selectbox_s">
                    <input type="hidden" class="province" value="-1"/>
                    <input type="hidden" class="city" value="-1"/>
                    <input type="hidden" class="area" value="-1"/>
                    <span class="" for="">省份：</span>
                    <div name="province" type="selectbox" class="btn-group inline "></div>
                    <span class="" for="">城市：</span>
                    <div name="city" type="selectbox" class="btn-group inline"></div>
                    <span class="" for="">区县：</span>
                    <div name="area" type="selectbox" class="btn-group inline"></div>
                </div>
                <button type="button" class="btn btn_white20 " style="vertical-align: 1px;" onclick="loadStation()">搜索
                </button>
            </div>
            <div class="row " style="margin-top: 10px;">
                <div class="arrow-right"></div>
                <div class="pull-left col-xs-6 col-sm-6">
                    <p class="text-left">选择站点</p>
                    <ul class="list-group choose-list">
                        <c:if test="${!empty stations}">
                            <c:forEach items="${stations}" var="st">
                                <li class="list-group-item" onclick="addSite(this)">${st.serverStationName}<input
                                        type="hidden" value="${st.serverStationCode}"/></li>
                            </c:forEach>
                        </c:if>
                    </ul>
                </div>
                <div class="pull-left col-xs-6 col-sm-6">
                    <p class="text-left">已选站点</p>
                    <ul class="list-group choosed-list" id="chosenSt">
                        <%--  <c:if test="${!empty stations}">
                        <c:forEach items="${stations}" var="st">
                            <li class="list-group-item">${st.serverStationName}<input type="hidden" value="${st.serverStationCode}"><span class="badge cancel_icon" onclick="cancelSite(this)"></span></li>
                        </c:forEach>
                    </c:if> --%>
                    </ul>
                </div>
            </div>
        </form>
        <div class="operate_btn pull-right">
            <button type="button" class="btn cancle_yes" onclick="openAccount(this)">确定开通</button>
            <button type="button" class="btn cancle_btn" onclick="resetAllOpts()">不开通</button>
        </div>
    </div>
</div>
<!-- 开通账号弹框 end -->
<!-- 工单详情 start -->
<div class="zhy_popa  dialog_2 " style="width:840px;margin-left: -420px;">
    <p class="color66"><span id="orderListName">${employee.employeeName}</span><span class="pull-right close_icon"
                                                                                     onclick="hidePop()"> </span></p>
    <div id="empOrderTb"></div>
    <div class="operate_btn text-right ">
        <button type="button" class="btn cancle_btn" onclick="hidePop()">关闭</button>
    </div>
    <div style="height: 25px;"></div>
</div>
<!-- 工单详情 end-->
<!-- 创建账号成功弹出 start -->
<div class="zhy_popa create_zh_s " style="width: 450px;margin-left: -225px;">
    <p class="color66">温馨提示<span class="pull-right close_icon"
                                 onclick="hidePop('${ctx}/pages/account/list.action')"></span></p>
    <div class="pop_content text-center">
        <p>尊敬的${loginName}，您已成功初始化账号<span id="createAccountName">${emplyee.employeeName}</span></p>
        <p>默认登录密码： <font class="colorbg">123456</font></p>
        <p>请登录系统及时修改密码，保护账号安全</p>
        </p>
        <div class="operate_btn pull-right">
            <button type="button" class="btn cancle_yes"
                    onclick="hidePop('${ctx}/pages/account/list.action')">关闭
            </button>
        </div>
    </div>
</div>
<!-- 实名认证用户没有权限 start-->
<div class="zhy_popa create_site_1 " style="width: 450px;margin-left: -225px;">
    <p class="color66">温馨提示<span class="pull-right close_icon" onclick="hidePop()"></span></p>
    <div class="pop_content text-center">
        <p>尊敬的${accountName}，您的账号创建权限已用完 </p>
        <p>如需创建更多的账号，请前往“官方应用”->“应用中心”中购买</p>
        <div class="operate_btn pull-right">
            <%--<button type="button" class="btn cancle_yes" onclick="window.parent.CreateDiv('center','/cloud-portal/order/myAppList','应用中心');" >立即购买</button>--%>
            <a class="btn cancle_yes" href="/cloud-portal/order/myAppList">立即购买</a>
            <button type="button" class="btn cancel" onclick="hidePop()">关闭</button>
        </div>
    </div>
</div>
<!-- 实名认证用户没有权限 end -->


<!-- 省市区联动 s -->
<script type="text/javascript" src="${res_uri}js/jquery.ganged.js"></script>
<script type="text/javascript" src="${res_uri}js/pro.js"></script><!--  省市区的json数据 -->
<!-- 省市区联动 e -->
<!--表单验证 s-->
<script type="text/javascript" src="${res_uri}js/jquery.validationEngine-zh_CN.js"></script>
<script type="text/javascript" src="${res_uri}js/jquery.validationEngine.js"></script>
<script>
    $('#jsAddress_3').ganged({'data': provinceList, 'selectAll': true, 'width': 111, 'height': 32});

    //展示已选站点
    function showSite() {
        $("#multi_site_block").html("");
        $("#multi_site_block").addClass("txt ml15").removeClass("ml150");
        var div = $("<div class='choosed-list-show'></div>");
        var more = $("<a href='javascript:void(0);' onclick='showList()' class='new_link2'>更多<i class='arrow_d_icon_0'></i></a>");
        // var more_choose =$("<a href='javascript:void(0);' class='new_link2'>继续添加</a>");
        var more_choose = $('<button type="button" class="btn_white2 margin10 site_add" onclick="deleteM(this,\'sitepop\')" ><i></i>继续添加</button>')
        var len = $(".choosed-list li").length;//已选站点的长度
        var choosed_li = $(".choosed-list li")//被选站点
        for (var i = 0; i < len; i++) {
            if (parseInt(i / 6) == 0) { //每六个一行
                var choosed_input = $(choosed_li[i]).find("input");
                var li = $("<div class='inline'></div>");
                var i_cancle = $("<i class='cancel_icon' value='" + choosed_input.val() + "' onclick='removeSite(this)'></i>");
                li.text(choosed_li.eq(i).text());
                li.append(i_cancle);
                div.append(li);
                if (len > 6) {
                    div.append(more);//如果有第二行才加更多
                }
            }
        }
        $("#multi_site_block").append(div);
        $("#multi_site_block").append(more_choose);
        hidePop();
    }

    // 移除展示站点
    function removeSite(obj) {
        $(obj).parent().remove();
        cancelSite($(".choosed-list li input[value=" + $(obj).attr("value") + "]").parent().find("span"));
        if ($(".new_link2").css('display') != 'none') {
            showSite()
        }
    }

    //展示  更多
    function showList() {
        var more_up = $("<a href='javascript:void(0);' onclick='hideList()' class='new_link2'>收起<i class='arrow_d_icon_1'></i></a>");
        var len = $(".choosed-list li").length;//已选站点的长度
        var choosed_li = $(".choosed-list li")//被选站点
        var row = parseInt((len - 6) / 6) + 1;//还剩几行没显示
        for (var j = 1; j <= row; j++) {
            var div = $("<div class='choosed-list-show'></div>");
            div.css('marginTop', "10px");
            for (var i = j * 6; i < len; i++) {
                if (parseInt(i / 6) == j) { //每六个一行
                    var choosed_input = $(choosed_li[i]).find("input");
                    var li = $("<div class='inline'></div>");
                    var i_cancle = $("<i class='cancel_icon' value='" + choosed_input.val() + "' onclick='removeSite(this)'></i>");
                    li.text(choosed_li.eq(i).text());
                    li.append(i_cancle);
                    div.append(li);
                    div.append(more_up);//最后一行加收起
                }
            }
            $("#multi_site_block .choosed-list-show:last").after(div);//添加到下一行
        }
        // $("#multi_site_block .choosed-list-show:last").after(div);//添加到下一行
        $("#multi_site_block .choosed-list-show:first").find(".new_link2").hide();
    }

    //展示  收起
    function hideList() {
        showSite();
        /*$(".choosed-list-show:gt(0)").remove();//除第一行外其其他行隐藏
         $("#multi_site_block .choosed-list-show:first").find(".new_link2").show();*/
    }

    //清除右侧已经选择的站点
    function clearChosenSt() {
        hidePop();
        //
        var chosenLi = $("#chosenSt").children("li");
        $.each(chosenLi, function (i, _li) {
            var _thidStCode = $(_li).find("input").val();
            cancelSite($(_li).find("span"));
        });

        var hasChoseSt = $(".choosed-list-show").children("div");
        var _canChoseLi = $(".choose-list").children("li");

        $.each(hasChoseSt, function (i, _div) {
            var chosenCode = $(_div).find("i").attr("value");
            $.each(_canChoseLi, function (j, _li) {
                var thisCode = $(_li).find("input").val();
                if (thisCode == chosenCode) {
                    addSite($(_li));
                }
            })
        });
    }

    function loadStation() {
        var province = $("div[name=province] input[name=province]").val();
        var city = $("div[name=city] input[name=city]").val();
        var area = $("div[name=area] input[name=area]").val();
        $.ajax({
            type: "POST",
            url: "/cloud-portal/station/accountStationList",
            dataType: "json",
            //contentType:"application/json",
            data: {
                "province": province,
                "city": city,
                "area": area,
                "pageSize": "10000"
            },
            success: function (dataStr) {
                $(".choose-list").empty();

                var choosed = $(".choosed-list li input");
                var map = {};
                for (var i = 0; i < choosed.length; i++) {
                    map[$(choosed[i]).val()] = 1;
                }
                var stations = dataStr.serviceStations;
                if (stations != null && stations.length > 0) {
                    for (var i = 0; i < stations.length; i++) {
                        if (map[stations[i].serverStationCode] == "1") {
                            continue;
                        }
                        var $li = $('<li class="list-group-item" onclick="addSite(this)">' + stations[i].serverStationName + '</li>');
                        $li.append('<input type="hidden" value="' + stations[i].serverStationCode + '"/>');
                        $(".choose-list").append($li)

                    }
                }
            }
        });
    }

    function addSite(obj) {
        $(obj).remove();//移除被选择项
        var str = $(obj).html();
        var $li = $("<li  class='list-group-item'></li>");
        var $span = $('<span class="badge cancel_icon" onclick="cancelSite(this)"></span>');
        $li.html(str);
        $span.appendTo($li);
        $(".choosed-list").prepend($li);
    }

    function cancelSite(obj) {
        var str = $(obj).parent().text();//添加取消项
        var stationCode = $(obj).parent().find("input");
        var $li = $('<li class="list-group-item" onclick="addSite(this)">' + str + '</li>');//添加取消项
        $li.append(stationCode);
        $(".choose-list").append($li)//添加取消项
        $(obj).parents("li").remove();
    }

    var currEmpId = ${empty employee ? 0 : employee.id};

    //显示弹框
    function showPop(obj, className) {
        //获取当前员工的姓名
        if (obj) {
            var thisTr = $(obj).parents("tr");
            var empName = $(thisTr).find("td:first").text();
            var phone = $(thisTr).find("td:eq(2)").text();
            currEmpId = $(thisTr).find("input").val();
            $("#joinName").html(empName);
            $("#leaveName").html(empName);
            $("#applyLeaveName").html(empName);
            $("#orderListName").html(empName);
            $("#empAcctName").html(empName);
            $("#deleteName").html(empName);
            $("#empPhone").html(phone);
            $("#createAccountName").html(empName);
        }
        $(".zhy_zhezhao_pop").show();
        var top = $('html', parent.document).scrollTop(); //兼容scrolltop写法
        var win_h = $("body", parent.document).height();
        $(".zhy_zhezhao_pop").height($("html").height());
        var this_h = $("." + className).height();
        var cha = win_h - this_h - 160;
        if (cha > 0) {
            top += cha / 2;
        } else {
            top += 0;
        }
        $("." + className).css("top", top).show();
    }

    // 隐藏修改弹框
    function hidePop(url) {
        $(".zhy_zhezhao_pop").hide();
        $(".zhy_popa").hide();
        if (url) {
            window.location.href = url;
        }
    }

    //还原设置项
    function resetAllOpts() {
        //
        $("#roleId").attr("value", 0).text("请选择");
        clearChosenSt();
    }

    //员工请假
    function empApplyLeave() {
        var leaveStartDate = $("#starttime").val();
        var leaveEndDate = $("#endtime").val();
        if (leaveStartDate == null || leaveStartDate == '') {
            zhyAlert("请输入请假开始时间！");
            return;
        }
        if (leaveEndDate == null || leaveEndDate == '') {
            zhyAlert("请输入请假结束时间！");
            return;
        }
        if (leaveEndDate < leaveStartDate) {
            zhyAlert("请假开始时间不能大于请假结束时间！");
            return;
        }
        hidePop();
        $.post("${ctx}/Employee/apply_leave", {
            'empId': currEmpId,
            'leaveStart': leaveStartDate + ":00",
            'leaveEnd': leaveEndDate + ":00"
        }, function (dataS) {
            var res = eval(dataS);
            if (res.resultCode == 'SUCC') {
                zhyAlert("操作成功！");
                hidePop();
                //var page=$("input[name='pageNum']").val();
                var timestamp = new Date().getTime();
                window.location.href = '${ctx}/Employee/list?pageNum='+${pageResult.pageNum}+
                '&t=' + timestamp;
            } else {
                zhyAlert(res.failureMessage);
            }
        }, "json");
    }

    //员工离职
    function changeStatus() {
        $.post("${ctx}/Employee/change_status", {'empId': currEmpId}, function (dataS) {
            var res = eval(dataS);
            if (res.resultCode == 'SUCC') {
                zhyAlert("操作成功！");
                hidePop();
                //var page=$("input[name='pageNum']").val();
                var timestamp = new Date().getTime();
                window.location.href = '${ctx}/Employee/list?pageNum='+${pageResult.pageNum}+
                '&t=' + timestamp;
            } else {
                hidePop();
                zhyAlert(res.failureMessage);
            }
        }, "json");
    }

    // 初始化密码
    function initPassword(employeeId, projectCode, phone) {
        $.post("${ctx}/Employee/init_employee_pwd", {
            'employeeId': employeeId,
            'projectCode': projectCode,
            'phone': phone
        }, function (dataS) {
            if (dataS.result) {
                zhyAlert(dataS.msg);
            } else {
                zhyAlert(dataS.msg);
            }
        }, "json");
    }

    //删除员工
    function deleteEmp() {
        $.post("${ctx}/Employee/delete", {'empId': currEmpId}, function (dataS) {
            var res = eval(dataS);
            if (res.resultCode == 'SUCC') {
                zhyAlert("操作成功！");
                hidePop();
                //var page=$("input[name='pageNum']").val();
                var timestamp = new Date().getTime();
                window.location.href = '${ctx}/Employee/list?pageNum='+${pageResult.pageNum}+
                '&t=' + timestamp;
            } else {
                zhyAlert(res.failureMessage);
            }
        }, "json");
    }

    //开通账号
    function openAccount(_this) {
        $(_this).attr('disabled', "true");//按钮不可用，防止重复提交
        var roleId = $("#roleId").attr("value");
        //var personCode = $("#personCode").val();
        //账户角色
        var _personRoles = [];
        //遍历所有的角色
        $("#personRole").find(":checked").each(function (i, roleInput) {
            _personRoles.push({"roleId": $(roleInput).val()});
        });
        //选择的站点
        var _psersonStation = [];
        $("#chosenSt li").each(function (i, liE) {
            _psersonStation.push({"serverStationCode": $(liE).find("input").val()});
        });

        var param = {};
        $.post("${ctx}/Employee/open_account", {
            'empId': currEmpId,
            "personRole": JSON.stringify(_personRoles),
            'personStations': JSON.stringify(_psersonStation)
        }, function (dataS) {
            var res = eval(dataS);
            if (res.resultCode == 'SUCC') {
                //zhyAlert("操作成功！");
                hidePop();
                showPop(undefined, 'create_zh_s');
            } else {
                $(_this).removeAttr("disabled");//按钮恢复可用
                if (res.failureCode == 'OVERLIMIT') {
                    hidePop();
                    showPop(undefined, 'create_site_1');
                    return;
                }
                zhyAlert(res.failureMessage);
            }
        }, "json");
    }

    //
    function empOrderDetail(_this) {
        showPop(_this, 'dialog_2');
        $.ajax({
            type: "POST",
            url: "${ctx}/Employee/emp_orders",
            data: {empId: currEmpId},
            dataType: "html",
            success: function (data) {
                $("#empOrderTb").empty().html(data);
            }
        });
    }

    var leaveId = 0;

    //销假操作
    function showEmpLeaveDetail(obj) {
        var thisTr = $(obj).parents("tr");
        var empName = $(thisTr).find("td:first").text();
        currEmpId = $(thisTr).find("input").val();
        $.post("${ctx}/Employee/leave_detail", {'empId': currEmpId}, function (dataS) {
            var res = eval(dataS);
            if (res.resultCode == 'SUCC') {
                leaveId = res.data.empLeaveId;
                $("#cancelLeaveName").html(empName);
                $("#leaveStart").html(res.data.leaveStartStr);
                $("#leaveEnd").html(res.data.leaveEndStr);
                showPop(undefined, "cancelLeave");
            } else {
                //$(_this).removeAttr("disabled");//按钮恢复可用
                zhyAlert(res.failureMessage);
            }
        }, "json");
    }

    //销假操作
    function empCancelLeave() {
        $.post("${ctx}/Employee/cancel_leave", {'empId': currEmpId, 'leaveId': leaveId}, function (dataS) {
            var res = eval(dataS);
            if (res.resultCode == 'SUCC') {
                zhyAlert("销假成功！");
                hidePop();
                window.location.href = '${ctx}/Employee/list?pageNum='+${pageResult.pageNum}+
                '&t=' + (new Date().getTime());
            } else {
                //$(_this).removeAttr("disabled");//按钮恢复可用
                zhyAlert(res.failureMessage);
            }
        }, "json");
    }

</script>

</body>
</html>